package cn.percent.sqlSession;

import cn.percent.config.Configuration;
import cn.percent.executor.CachingExecutor;


public class DefaultSqlSessionFactory implements SqlSessionFactory{
    private Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }

    @Override
    public SqlSession openSession() {

        if (configuration.isCacheEnabled()) {
            CachingExecutor cachingExecutor = new CachingExecutor(configuration);
            return new DefaultSqlSession(configuration,cachingExecutor);
        }
        return new DefaultSqlSession(configuration);
    }
}
